package com.greendragon.persistence.domain; 

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.IndexColumn;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-23 下午05:37:16
 * 
 */
@Entity
@Table(name="album")
public class Album implements Serializable{
	private static final long serialVersionUID = 7094350903197602959L;
	
	private Long id;
	private String name;													//名称
	private String description;												//描述
	private Integer photoCount = new Integer(0);							//照片数目
	private List<Resource> photos;											//相册照片
	private Resource coverImg;												//封面照片
	private User author;													//作者	
	private Date createdAt;													//创建日期
	private Date modifiedAt;												//最后修改日期
	
	public Album(){}

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="name", length=100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Lob
	@Column(name="description")
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name="photo_count")
	public Integer getPhotoCount() {
		return photoCount;
	}

	public void setPhotoCount(Integer photoCount) {
		this.photoCount = photoCount;
	}

	@OneToMany(fetch=FetchType.LAZY)
	@JoinTable(
        name="album_photo",
        joinColumns = @JoinColumn( name="album_id"),
        inverseJoinColumns = @JoinColumn( name="image_id")
	)
	@IndexColumn(name="position")
	public List<Resource> getPhotos() {
		return photos;
	}

	public void setPhotos(List<Resource> photos) {
		this.photos = photos;
	}

	@ManyToOne
    @JoinColumn(name="image_id")
	public Resource getCoverImg() {
		return coverImg;
	}

	public void setCoverImg(Resource coverImg) {
		this.coverImg = coverImg;
	}

	@ManyToOne
    @JoinColumn(name="author_id")
	public User getAuthor() {
		return author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	@Column(name="createdAt")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	@Column(name="modifiedAt")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getModifiedAt() {
		return modifiedAt;
	}

	public void setModifiedAt(Date modifiedAt) {
		this.modifiedAt = modifiedAt;
	}
	
}
 